﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Apollo;

namespace Apollo.Website
{
    public partial class Controls_MessageList : System.Web.UI.UserControl
    {
        public int MessagesCount { get { return messages.Count; } }

        protected IList<ActionMessage> messages = new List<ActionMessage>();

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        public void AddMessage(ActionMessage message)
        {
            this.messages.Add(message);
        }

        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);

            LiteralMessages.Text = "";

            if (this.messages.Count > 0)
            {
                foreach (ActionMessage msg in this.messages)
                    LiteralMessages.Text += string.Format("<li><img src=\"css/icons/{0}.png\" border=\"0\" alt=\"\" /> <span class=\"{0}\">{1}</span></li>"
                        , msg.Type.ToString().ToLower(), msg.Message);
                Messages.Visible = true;
            }
            else
                Messages.Visible = false;
        }
    }
}